package com.ailikes.lottery.analysis.reptile;

import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.pipeline.ConsolePipeline;
import us.codecraft.webmagic.processor.PageProcessor;

import java.util.List;

public class DaLeTouProcesser implements PageProcessor {

    private Site site = Site.me().setDomain("kaijiang.aicai.com");

    @Override
    public void process(Page page) {
        List<String> links = page.getHtml().links().regex("https://kaijiang.aicai.com/").all();
        page.addTargetRequests(links);
        page.putField("periods", page.getHtml().xpath("//div[3]/div[4]/div[2]/ul/li[2]/p[1]/strong/text()").toString());
        page.putField("1", page.getHtml().xpath("//div[3]/div[4]/div[2]/ul/li[2]/div[1]/div/i[1]/text()").toString());
        page.putField("2", page.getHtml().xpath("//div[3]/div[4]/div[2]/ul/li[2]/div[1]/div/i[2]/text()").toString());
        page.putField("3", page.getHtml().xpath("//div[3]/div[4]/div[2]/ul/li[2]/div[1]/div/i[3]/text()").toString());
        page.putField("4", page.getHtml().xpath("//div[3]/div[4]/div[2]/ul/li[2]/div[1]/div/i[4]/text()").toString());
        page.putField("5", page.getHtml().xpath("//div[3]/div[4]/div[2]/ul/li[2]/div[1]/div/i[5]/text()").toString());
        page.putField("6", page.getHtml().xpath("//div[3]/div[4]/div[2]/ul/li[2]/div[1]/div/i[6]/text()").toString());
        page.putField("7", page.getHtml().xpath("//div[3]/div[4]/div[2]/ul/li[2]/div[1]/div/i[7]/text()").toString());
        ResultItems r = page.getResultItems();

        System.out.println(r.get("periods").toString());
        System.out.println(r.get("1").toString());
        System.out.println(r.get("2").toString());
        System.out.println(r.get("3").toString());
        System.out.println(r.get("1").toString());
        System.out.println(r.get("1").toString());
        System.out.println(r.get("1").toString());
    }

    @Override
    public Site getSite() {
        return site;

    }

    public static void main(String[] args) {
        Spider.create(new DaLeTouProcesser()).addUrl("https://kaijiang.aicai.com/").addPipeline(new ConsolePipeline()).run();

    }
}